using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BoarChaseState : BaseState {

    public override void OnEnter(Enemy enemy) {
        currentEnemy = enemy;
        Debug.Log("Chase");
        currentEnemy.currentSpeed = currentEnemy.chaseSpeed;
        currentEnemy.ani.SetBool("isRun", true);
    }

    public override void LogicUpdate() {
        // 如果丢失目标超过一定时间则重新回到巡逻状态
        if (currentEnemy.lostTimeCounter <= 0) {
            currentEnemy.SwitchState(NPCState.Patrol);
        }

        // 追击状态下撞墙直接回头
        if (!currentEnemy.physicsCheck.isGround || (currentEnemy.physicsCheck.touchLeftWall && currentEnemy.faceDir.x < 0 || currentEnemy.physicsCheck.touchRightWall && currentEnemy.faceDir.x > 0)) {
            currentEnemy.transform.localScale = new Vector3(currentEnemy.faceDir.x, 1, 1);
        }
    }

    public override void PhysicsUpdate() {
        
    }

    public override void OnExit() {
        currentEnemy.ani.SetBool("isRun", false);
        Debug.Log("Chase Exit");
    }

}
